package com.xerokhan.diary.util;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Random;

import com.xerokhan.file.File;
import com.xerokhan.generator.Generator;

public class Test {

	/**
	 * @param args
	 * @throws SQLException
	 */
	public static void main(String[] args) throws SQLException {
		System.out.println("use daybook;");
		// generatedAddressInsertScript();
		// generatedUserContactInsertScript();
		generateTodo();
	}

	public static void generateTodo() {
		ArrayList<String> lines = File.getLines("todo");
		for (int i = 0; i < lines.size(); i++) {
			ArrayList<Integer> t = new ArrayList<Integer>();
			int size = Generator.nextInt(51);
			for (int j = 0; j < size; j++) {
				String[] vals = lines.get(i).split(",");
				String q = "insert into todo (summary,description ,start_time, end_time, status, importance, user_id) values('" + vals[0] + "','" + vals[1]
						+ "','" + vals[2] + "','" + vals[3] + "'," + vals[4] + "," + vals[5] + "," + vals[6]+");";
				System.out.println(q);

				// String a = GeneratorData.TODO_SUBJECT[j] + ",," +
				// Generator.nextDate(2008, 2) + "," + Generator.nextDate(2010,
				// 2) + ","
				// + Generator.nextInt(100) + "," + Generator.nextInt(10) + ","
				// + i;
				// System.out.println(a);
			}
		}

	}

	public static void generatedAddressInsertScript() {
		System.out.println("-- ----------------------- users -----------------------------");

		ArrayList<String> lines = File.getLines("address");
		for (int i = 0; i < lines.size(); i++) {
			String[] vals = lines.get(i).split(",");
			String q = "insert into address (address, phone, city, district, country) values('" + vals[0] + "','" + vals[1] + "','" + vals[2] + "','" + vals[3]
					+ "','" + vals[4] + "');";
			System.out.println(q);
		}
	}

	public static void generatedUserInsertScript() {
		System.out.println("-- ----------------------- users -----------------------------");

		ArrayList<String> lines = File.getLines("user");
		for (int i = 0; i < lines.size(); i++) {
			String[] vals = lines.get(i).split(",");
			String q = "insert into user (user_number, first_name, last_name,email,dob,gender,date_of_joining) values('"
					+ (vals[5].replaceAll("-", "") + (i + 1)) + "','" + vals[0] + "','" + vals[1] + "','" + vals[2] + "','" + vals[3] + "','" + vals[4] + "','"
					+ vals[5] + "');";
			System.out.println(q);
		}
	}

	public static void generatedUserContactInsertScript() {

		ArrayList<String> lines = File.getLines("user");
		System.out.println("-- ----------------------- contacts -----------------------------");
		int count = lines.size();
		String[] category = { "Family", "School", "Office", "Friends" };
		String[] type = { "Wife", "Girl Friend", "Father", "Mother", "Sister", "Brother" };

		Random r = new Random();
		for (int i = 0; i < count; i++) {
			int contactCount = r.nextInt() % (count - 1);
			ArrayList<Integer> contacts = new ArrayList<Integer>();
			for (int j = 0; j < contactCount; j++) {
				int c = Math.abs(r.nextInt() % (contactCount));
				if (!contacts.contains(c) && c != i && c != 0) {
					contacts.add(c);
				}
			}
			for (int j = 0; j < contacts.size(); j++) {
				String a = category[Math.abs(r.nextInt() % category.length)];
				String b = type[Math.abs(r.nextInt() % type.length)];
				int con = contacts.get(j);
				String q = "insert into contact (user_id, contact_id,category,type) values(" + (i + 1) + "," + con + ",'" + a + "','" + b + "');";
				System.out.println(q);
			}
		}
	}
}
